package aop03;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

import java.lang.reflect.Method;
import java.util.Date;

/**
 * Auther:ws@itany.com
 * Date:20-9-15 上午9:19
 * Version:1.0
 * Description:
 */

public class AroundAdvice implements MethodInterceptor {

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        //获取目标类
        Object target = invocation.getThis();
        //获取目标方法
        Method method = invocation.getMethod();
        //获取目标方法的参数
        Object[] args = invocation.getArguments();


        Object result = null;

        try {
            System.out.println("环绕通知之前置通知");
            // 执行目标方法
            long date1 = new Date().getTime();
            result = invocation.proceed();
            System.out.println("环绕通知之后置通知");
            long date2 = new Date().getTime();
            System.out.print("时间"+(date2 - date1));
        } catch (Throwable throwable) {
            System.out.println("环绕通知之异常通知");
        }
        return result;
    }
}
